import datetime
import functools

import settings

"""
############# 当前包中定义的任何函数的返回值只能是 str、int、float、dict、list 中的一种  ##################
"""


def type_check(original):
    @functools.wraps(original)
    def function(*args, **kwargs):
        if not isinstance(ret := original(*args, **kwargs), (str, int, float, dict, list)):
            raise TypeError(f"函数 {original.__name__} 返回倯合法类型为 str, int, float, dict, list 中的一种")
        return ret

    return function


@type_check
def date(year=None, mouth=None, day=None):
    now = datetime.datetime.now()
    year = year or now.year
    mouth = mouth or now.month
    day = day or now.day
    return datetime.datetime(year=year, month=mouth, day=day).strftime(settings.TIME_FMT)


@type_check
def login_data(account) -> dict:
    """
    :return {"username": "", "password": ""}
    """
    # if (res := os.environ.get(account), None) is None:
    #     raise OSError(f"未在环境变量中配置 {account} 账号")
    # return json.loads(res)
    return {"username": "18913079151", "password": "Zhaojian.320924"}


def __reflect_module_attribute__(string):
    return eval(string)
